package com.efuture.androidmvpdemo.login

import com.efuture.androidmvpdemo.ui.base.BasePresenter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel

/**

 *@description:TODO
 * @author: zhaoshanshan
 * @date: 2022/3/26 4:21 下午

 */
class LoginPresenter(var loginView: LoginView?, val loginInteractor: LoginInteractor):LoginInteractor.OnLoginFinishedListener,BasePresenter {


    fun login(mainScope: CoroutineScope,username: String, password: String){
        loginInteractor.login(mainScope,username,password,this)
    }


    override fun onFail(reason:String) {
        loginView?.loginFail(reason)
    }

    override fun onSuccess() {
        loginView?.loginSuccess()
        loginView?.clearInputData()
    }

    override fun onDestroyView(mainScope: CoroutineScope) {
        loginView = null
        mainScope?.cancel()
    }


}